#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    string longestCommonPrefix(vector<string>& strs) {

        int n = 0;
        char ch = strs[0][0];
        int i = 0, j = 0;
        string str;
        while (1) {
            for (i = 0; i < strs.size(); i++) {
                if (strs[i][j] != ch || strs[i][j] == '\0')
                    break;
            }
            if (i == strs.size()) {
                str += ch;
                j++;

                ch = strs[0][j];
            }
            else break;
        }
        return str;
    }
};